<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>库存管理</title>
	<meta name="decorator" content="default"/>
	<style type="text/css">
		.table td {
			vertical-align: middle;
			background-color: #FFF;
			border: 0px;
			padding: 0px
		}
		.bg_white{background-color: white; color: red}
		#sortSearch li{border-right: 1px solid #DDD;padding: 5px 15px;list-style-type:none;float: left}
		.twoClass label{border: 1px solid #DDD; margin-left: 0px; margin-top: 5px;padding: 0px 5px;}
		.bg_color{background-color: #A1A1FF;}
		#one li a{padding-top: 0px; padding-bottom: 0px;}
	</style>
	<script type="text/javascript">
		var _lastPage="false";
		$(document).ready(function() {
			_lastPage = ${page.lastPage};
		});
		var isLoadOver=0;//判断滑动是否已加载完成
		$(window).scroll(function(){  
		    // 当滚动到最底部以上100像素时， 加载新内容  
		    if ($(document).height() - $(this).scrollTop() - $(this).height()<100){
		    	if(isLoadOver == 0){
		    		isLoadOver = 1;
			    	loadMore();  
		    	}
		    }
		}); 
		//加载更多
		function loadMore(){
			if(_lastPage){
				return;
			}
			setTimeout(function () {
				//获取下一页数据
				$("#pageNo").val(parseInt($("#pageNo").val())+1);
				var param = "pageNo="+$("#pageNo").val()+"&pageSize="+$("#pageSize").val();
				param += "&oneClassify="+$("#oneClassify").val();
				param += "&twoClassify="+$("#twoClassify").val();
				//异步获取更多
				$.ajax({
					type: 'get',
					url: '${ctx}/ivm/product/list/more',
					data: param,
					dataType: 'json',
					success: function(data){
						if(data!=null){
							var list = data.list;
							if(data.lastPage){
							 	_lastPage = data.lastPage;
							}
							for(var i=0; i<list.length; i++){
								var product = list[i];
								var html = '<table id="contentTable" class="table table-bordered table-condensed" style="border-top: 0px;margin-bottom:5px">';
								html += '<colgroup><col width="169px"/><col width="119px"/><col width="119px"/><col width="119px"/><col width="119px"/><col width="119px"/><col width="305px"/></colgroup>';
								html += '<tr>';
								html += '<td rowspan="5"><a href="${ctx}/ivm/product/form?id='+product.id+'"><img id="photo" src="${ctx}/download?filePath='+product.logoUrl+'" style="width:149px;height:96px " /></a></td>';
								html += '<td>'+product.code+'</td>';
								html += '<td colspan="2"><a href="${ctx}/ivm/product/form?id='+product.id+'">'+product.name+'</a></td>';
								html += '<td></td>';
								html += '<td><label class="color-green" onclick="openSaleState(\''+product.id+'\')">';
								if(product.openState==1){
									html += '正在销售';
								}else{
									html += '待售';
								}
								html += '</label></td>';
								html += '<td><label class="color-green" onclick="openIntoInventory(\''+product.id+'\')">入库</label></td>';
								html += '</tr><tr>';
								html += '<td colspan="3">'+product.assisTitle+'</td><td></td>';
								html += '<td><label class="color-green" onclick="showProductSupplier(\''+product.id+'\')">销售市场</label></td>';
								html += '<td><label class="color-green" onclick="openOutInventory(\''+product.id+'\')">库存处理</label></td>';
								html += '</tr><tr>';
								html += '<td>售价：'+product.price+'元</td>';
								html += '<td>进价：暂无</td>';
								html += '<td>市场价：'+product.marketPrice+'元</td>';
								html += '<td></td>';
								html += '<td><label class="color-green" onclick="openPayState(\''+product.id+'\')">';
								if(product.toPay=='0'){
									html += '网付';
								}else{
									html += '网付/到付';
								}
								html += '</label></td>';
								html += '<td><label class="color-green" onclick="showInOrOutDetail(\''+product.id+'\', \''+product.name+'\')">进出库记录</label></td>';
								html += '</tr><tr>';
								html += '<td>毛利率：</td>';
								html += '<td>损耗率：</td>';
								html += '<td></td>';
								html += '<td></td>';
								if(product.purchaseNum==0){
									html += '<td>不限购</td>';
								}else{
									html += '<td>限购数量：'+product.purchaseNum+'</td>';
								}
								html += '<td></td>';
								html += '</tr><tr>';
								html += '<td>售出：无</td>';
								html += '<td>浏览：无</td>';
								html += '<td>库存：'+product.stock+'</td>';
								html += '<td colspan="3"></td>';
								html += '</tr><tr height="5px"></tr>';
				    			html += '</table>';
				    			$("#listForm").append(html);
							}
						}
						isLoadOver = 0;
					},
					failure: function(){
					}
				});
			}, 500);
			isLoadOver = 1;
		}
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
        //选择一级分类
		function checkOneClassify(obj,id){
			$("#oneClassify").val(id);
			$("#twoClassify").val('');
			$('#searchForm1').submit();
			//处理style
		}
		//选择二级分类
		function checkTwoClassify(obj,id){
			$("#twoClassify").val(id);
			$('#searchForm1').submit();
		}
		
		function showIntoInventory(productId){
			top.$.jBox.defaults.top="8%";
			top.$.jBox.open("iframe:${ctx}/ivm/inventory/showIntoInventory?productId="+productId, "商品入库",$(top.document).width()-700,$(top.document).height()-100,{
				buttons:{"确定":false}, loaded:function(h){
					$(".jbox-content", top.document).css("overflow-y","hidden");
				}
			});
		}
		
		function showInventoryDetail(productId, text){
			top.$.jBox.defaults.top="8%";
			top.$.jBox.open("iframe:${ctx}/ivm/inventory/showInventoryDetail?product.id="+productId, text+"—入库记录",$(top.document).width()-500,$(top.document).height()-100,{
				buttons:{"确定":false}, loaded:function(h){
					$(".jbox-content", top.document).css("overflow-y","hidden");
				}
			});
		}
		
		function showOutDetail(productId, text){
			top.$.jBox.defaults.top="8%";
			top.$.jBox.open("iframe:${ctx}/ivm/inventory/showOutDetail?product.id="+productId, text+"—出库记录",$(top.document).width()-500,$(top.document).height()-100,{
				buttons:{"确定":false}, loaded:function(h){
					$(".jbox-content", top.document).css("overflow-y","hidden");
				}
			});
		}
		//打开销售状态入口
		function openSaleState(id){
			top.$.jBox.defaults.top="25%";
			top.$.jBox.open("iframe:${ctx}/ivm/product/showOpenState?id="+id, "销售状态",$(top.document).width()-800,$(top.document).height()-300,{
				buttons:{"确定":false}, loaded:function(h){
					$(".jbox-content", top.document).css("overflow-y","hidden");
				}
			});
		}
		//打开付款方式入口
		function openPayState(id){
			top.$.jBox.defaults.top="25%";
			top.$.jBox.open("iframe:${ctx}/ivm/product/showPayState?id="+id, "支付方式",$(top.document).width()-800,$(top.document).height()-300,{
				buttons:{"确定":false}, loaded:function(h){
					$(".jbox-content", top.document).css("overflow-y","hidden");
				}
			});
		}
		//打开商品入库入口
		function openIntoInventory(id){
			top.$.jBox.defaults.top="8%";
			top.$.jBox.open("iframe:${ctx}/ivm/inventory/showIntoInventory?productId="+id, "商品入库",$(top.document).width()-700,$(top.document).height()-100,{
				buttons:{"确定":false}, loaded:function(h){
					$(".jbox-content", top.document).css("overflow-y","hidden");
				}
			});
		}
		//打开商品出库入口
		function openOutInventory(id){
			top.$.jBox.defaults.top="8%";
			top.$.jBox.open("iframe:${ctx}/ivm/inventory/showOutInventory?productId="+id, "商品出库",$(top.document).width()-700,$(top.document).height()-100,{
				buttons:{"确定":false}, loaded:function(h){
					$(".jbox-content", top.document).css("overflow-y","hidden");
				}
			});
		}
		//打开摸价周几设置入口
		function openPriceCycleSet(id){
			top.$.jBox.defaults.top="28%";
			top.$.jBox.open("iframe:${ctx}/ivm/product/showPriceCycleSet?id="+id, "摸价周期",$(top.document).width()-800,$(top.document).height()-400,{
				buttons:{"确定":false}, loaded:function(h){
					$(".jbox-content", top.document).css("overflow-y","hidden");
				}
			});
		}
		//打开进出库记录入口
		function showInOrOutDetail(id, name){
			top.$.jBox.defaults.top="8%";
			top.$.jBox.open("iframe:${ctx}/ivm/inventory/showInOrOutDetail?productId="+id, name+"_进出库记录",$(top.document).width()-500,$(top.document).height()-100,{
				buttons:{"确定":false}, loaded:function(h){
					$(".jbox-content", top.document).css("overflow-y","hidden");
				}
			});
		}
		//打开市场价记录入口
		function openMarketPrice(id, price, name){
			top.$.jBox.defaults.top="8%";
			top.$.jBox.open("iframe:${ctx}/ivm/product/showMarketPrice?product.id="+id, name+"_市场价记录",$(top.document).width()-500,$(top.document).height()-100,{
				buttons:{"确定":false}, loaded:function(h){
					$(".jbox-content", top.document).css("overflow-y","hidden");
				}
			});
		}
		//打开销售市场入口
		function showProductSupplier(id){
			top.$.jBox.defaults.top="25%";
			top.$.jBox.open("iframe:${ctx}/ivm/product/showProductSupplier?id="+id, "销售市场",$(top.document).width()-800,$(top.document).height()-300,{
				buttons:{"确定":false}, loaded:function(h){
					$(".jbox-content", top.document).css("overflow-y","hidden");
				}
			});
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/ivm/inventory/">库存管理</a></li>
	</ul>
	<form:form id="searchForm" modelAttribute="product" action="${ctx}/ivm/inventory/" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<input id="searchParam" name="searchParam" type="text" value="${searchParam }" style="width: 410px;" placeholder="请输入商品名称"/>
		&nbsp;<input id="btnSubmit" class="btn btn-primary" type="submit" value="搜索"/>
		&nbsp;<input id="btnSubmit" class="btn btn-primary" type="button" value="入库" onclick="showIntoInventory('')"/>
		<label>状态：</label>
		<span><form:radiobutton onclick="$('#searchForm').submit();" path="stock" value="3" label="全部" htmlEscape="false"/></span>
		<span><form:radiobutton onclick="$('#searchForm').submit();" path="stock" value="1" label="正常" htmlEscape="false"/></span>
		<span><form:radiobutton onclick="$('#searchForm').submit();" path="stock" value="2" label="售空" htmlEscape="false"/></span>
	</form:form>
	<form:form id="searchForm1" modelAttribute="product" action="${ctx}/ivm/inventory/" method="post" class="breadcrumb form-search" style="margin-top:-15px">
		<input type="hidden" id="oneClassify" name="oneClassify" value="${oneClassify }"/>
		<input type="hidden" id="twoClassify" name="twoClassify" value="${twoClassify }"/>
		<ul class="nav nav-tabs" style="margin-bottom: 0px;" id="one">
			<li class="${oneClassify==''?'active':''}"><a href="#" onclick="checkOneClassify(this,'')">全部</a></li>
			<c:forEach items="${fns:getClassifyOneList()}" var="classify">
			<li class="${classify.id==oneClassify?'active':''}"><a href="#" onclick="checkOneClassify(this,'${classify.id}')">${classify.name }</a></li>
			</c:forEach>
		</ul>
		<table width="100%" cellpadding="0" cellspacing="0" border="0">
			<tr>
				<td class="twoClass"><label class="${twoClassify==''?'bg_color':'' }" onclick="checkTwoClassify(this,'')">全部</label>
					<c:forEach items="${fns:getClassifyTwoList(oneClassify)}" var="classifyTwo">
						<label class="${classifyTwo.id==twoClassify?'bg_color':''}" onclick="checkTwoClassify(this,'${classifyTwo.id}')">${classifyTwo.name }</label>
					</c:forEach>
				</td>
			</tr>
		</table>
	</form:form>
	<tags:message content="${message}"/>
	<form id="listForm" method="post">
	<c:forEach items="${page.list}" var="product">
	<table id="contentTable" class="table table-bordered table-condensed" style="border-top: 0px;margin-bottom:5px">
		<colgroup>
			<col width="169px"/><col width="119px"/><col width="119px"/><col width="119px"/><col width="119px"/><col width="119px"/><col width="305px"/>
		</colgroup>
		<tr>
			<td rowspan="5"><a href="${ctx}/ivm/product/form?id=${product.id}"><img id="photo" src="${ctx}/download?filePath=${product.logoUrl }" style="width:149px;height:96px " /></a></td>
			<td>${product.code}</td>
			<td colspan="2"><a href="${ctx}/ivm/product/form?id=${product.id}">${product.name}</a></td>
			<td></td>
			<td><label class="color-green" onclick="openSaleState('${product.id}')">${product.openState==1?'正在销售':'待售' }</label></td>
			<td><label class="color-green" onclick="openIntoInventory('${product.id}')">入库</label></td>
		</tr>
		<tr>
			<td colspan="3">${product.assisTitle}</td>
			<td></td>
			<td><label class="color-green" onclick="showProductSupplier('${product.id}')">销售市场</label></td>
			<td><label class="color-green" onclick="openOutInventory('${product.id}')">库存处理</label></td>
		</tr>
		<tr>
			<td>售价：${product.price }元</td>
			<td>进价：暂无</td>
			<td>市场价： ${product.marketPrice }元</td>
			<td></td>
			<td><label class="color-green" onclick="openPayState('${product.id}')">${product.toPay=='0'?'网付':'网付/到付' }</label></td>
			<td><label class="color-green" onclick="showInOrOutDetail('${product.id}', '${product.name}')">进出库记录</label></td>
		</tr>
		<tr>
			<td>毛利率：</td>
			<td>损耗率：</td>
			<td></td>
			<td></td>
			<c:if test="${product.purchaseNum==0}">
				<td>不限购</td>
			</c:if>
			<c:if test="${product.purchaseNum>0}">
				<td>限购数量：${product.purchaseNum }</td>
			</c:if>
			<td></td>
		</tr>
		<tr>
			<td>售出：无</td>
			<td>浏览：无</td>
			<td>库存：${product.stock } ${product.specUnit.name }</td>
			<td colspan="3"></td>
		</tr>
		<tr height="5px"></tr>
	</table>
	</c:forEach>
	</form>
</body>
</html>
